package com.yunhe.policyfulfillment.authority.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.policyfulfillment.authority.domain.PolicyCompanyUser;
import com.yunhe.policyfulfillment.authority.domain.PolicyUser;
import com.yunhe.policyfulfillment.authority.model.DisableRecoveryUser;
import com.yunhe.policyfulfillment.authority.model.PolicyCompanyUserQueryCondition;
import com.yunhe.policyfulfillment.authority.service.PolicyCompanyUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: PolicyCompanyUserController
 * @Description:
 * @author: GongDaCheng
 * @Date: 9:46 2021/9/18
 */
@Api(value = "PolicyCompanyUser", description = "政策兑现企业用户", tags = {"Model_Policy_Company_User"})
@RestController
@RequestMapping(value = "/policyCompanyUser")
public class PolicyCompanyUserController {

    @Autowired
    private PolicyCompanyUserService policyCompanyUserService;

    @ApiOperation("新增政策兑现企业用户")
    @PostMapping("/createPolicyCompanyUser")
    public ResponseEntity<ResultObject> createPolicyCompanyUser(@RequestBody PolicyCompanyUser policyCompanyUser) throws ArgumentErrorException {
        policyCompanyUserService.createPolicyCompanyUser(policyCompanyUser);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据id删除企业用户")
    @DeleteMapping("/deletePolicyCompanyUser")
    public ResponseEntity<ResultObject> deletePolicyCompanyUser(@RequestBody List<Long> ids){
        policyCompanyUserService.deletePolicyCompanyUser(ids);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("更新企业用户")
    @PostMapping("/updatePolicyCompanyUser")
    public ResponseEntity<ResultObject> updatePolicyCompanyUser(@RequestBody PolicyCompanyUser policyCompanyUser) throws ArgumentErrorException {
        policyCompanyUserService.updatePolicyCompanyUserByPrimaryKey(policyCompanyUser);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据id查询企业用户")
    @GetMapping("/findPolicyCompanyUserById")
    public ResponseEntity<ResultObject<PolicyUser>> findPolicyCompanyUserById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(policyCompanyUserService.searchPolicyCompanyUserByPrimaryKey(id)),HttpStatus.OK);
    }

    @ApiOperation("根据条件查询企业用户")
    @PostMapping("/findPolicyCompanyUserByCondition")
    public ResponseEntity<ResultObject<List<PolicyUser>>> findPolicyCompanyUserByCondition(@RequestBody PolicyCompanyUserQueryCondition policyCompanyUserQueryCondition) throws ArgumentErrorException {
        PageResult pageResult = policyCompanyUserService.findPolicyCompanyUserByCondition(policyCompanyUserQueryCondition);
        return new ResponseEntity(new ResultObject<>(pageResult), HttpStatus.OK);
    }

    @ApiOperation("重置密码")
    @PostMapping(value = "/resetPassword")
    public ResponseEntity<ResultObject<String>> resetPassword(@RequestBody List<Long> ids) throws ArgumentErrorException {
        return new ResponseEntity(new ResultObject<>(policyCompanyUserService.resetPassword(ids)), HttpStatus.OK);
    }

    @ApiOperation("禁用/恢复账号")
    @PostMapping(value = "/disableRecoveryCompanyUser")
    public ResponseEntity<ResultObject> disableRecoveryCompanyUser (@RequestBody DisableRecoveryUser disableRecoveryUser) throws ArgumentErrorException {
        policyCompanyUserService.disableRecoveryCompanyUser(disableRecoveryUser);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }
}
